var ApprovalProcessAudit = {
    id: "ApprovalProcessAuditTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}

ApprovalProcessAudit.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: '客户姓名', field: 'customerName', align: 'center', valign: 'middle',  width: 100,sortable: true},
        {title: '手机号码', field: 'customerPhone', align: 'center', valign: 'middle',  width: 140,sortable: true},
        {title: '门店', field: 'outpatientName', align: 'center', valign: 'middle',  width: 100,sortable: true},
        {title: '操作人', field: 'person', align: 'center', valign: 'middle', width: 90, sortable: true},
        {title: '建档人', field: 'name', align: 'center', valign: 'middle',  width: 90,sortable: true},
        {title: '审核详情', field: 'content', align: 'center', valign: 'middle',  width: 220,sortable: true,
            formatter: function (value, row, index) {
                return '<span title="'+value+'">'+value+'</span>'
            },
            cellStyle: function (value, row, index) {
                return {css: {"overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}
            }
        },
        {title: '提交时间', field: 'createtime', align: 'center', valign: 'middle',  width: 170,sortable: true,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle',  width: 120,sortable: true,
            formatter: function (value, row, index) {
                return '<span title="'+value+'">'+value+'</span>'
            },
            cellStyle: function (value, row, index) {
                return {css: {"overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}
            }
        },
        {title: '是否成功', field: 'succeed', align: 'center', valign: 'middle',  width: 100,sortable: true}
    ];
    return columns;
};

ApprovalProcessAudit.search = function () {
    ApprovalProcessAudit.table.refresh({query: ApprovalProcessAudit.formParams()});
};

ApprovalProcessAudit.formParams = function () {
    var queryData = {};
    queryData['customerPhone'] = $("#customerPhone").val();
    queryData['customerName'] = $("#customerName").val();
    queryData['outpatientName'] = $("#outpatientName").val();  //门诊
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
};

ApprovalProcessAudit.resetSearch = function () {
    $("#customerPhone").val("");
    $("#customerName").val("");
    $("#outpatientName").val("");
    $("#startTime").val("");
    $("#endTime").val("");
    ApprovalProcessAudit.search();
};
$(function () {
    document.getElementById("startTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endTime").value =myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    var defaultColunms = ApprovalProcessAudit.initColumn();
    var table = new BSTable(ApprovalProcessAudit.id, "/approvalProcessLog/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(ApprovalProcessAudit.formParams());
    ApprovalProcessAudit.table = table.init();
    ApprovalProcessAudit.search();
    $(document).on('click','#laydate_clear,#laydate_today,#laydate_ok',function () {ApprovalProcessAudit.search();});
    checkDate = function () {ApprovalProcessAudit.search();};
});